package com.es.common;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 通用存储
 *
 * @author Will
 */
public class Cache {

    private static Map<String, Object> cache = new ConcurrentHashMap<>();

    public static Map<String, Object> getCache() {
        return cache;
    }

    public static void setCache(Map<String, Object> cache) {
        Cache.cache = cache;
    }

    public static void addCache(String key, Object object) {
        if (containsKey(key)) {
            Cache.cache.put(key, object);
        } else {
            Cache.cache.replace(key, object);
        }
    }

    public static void addCache(Map<String, Object> map) {
        cache.putAll(map);
    }

    public static boolean containsKey(String key) {
        return Cache.cache.containsKey(key);
    }

    public static Object get(String key) {
        return Cache.cache.get(key);
    }

}
